/* BSD 3-Clause License Copyright (c) 2026, Canva Pty Ltd. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 'use strict'; const { Document } = require('/document.js'); const { DocumentCommand, CompoundCommandBuilder } = require('/commands.js'); const { CurveBuilder, PolyCurve } = require('/geometry.js'); const doc = Document.current; const m1 = 1; const m2=-1; // multiplier applied to the s1, s2 etc // variables added by me ... const s1=0;const s2=300;const s3=0;const s4=0;const s5=0;const s6=0;const s7=0;const s8=0;const s9=0;const s10=0;const s11=-300;const s12=0; // bowl /** PRESETS created by me - please add your own or just use the ones below const s1=0;const s2=0;const s3=-100;const s4=-50;const s5=0;const s6=0;const s7=0;const s8=0;const s9=50;const s10=100;const s11=0;const s12=0; // criss cross const s1=0;const s2=0;const s3=-100;const s4=0;const s5=0;const s6=0;const s7=0;const s8=0;const s9=100;const s10=0;const s11=0;const s12=0; // horizontal const s1=0;const s2=0;const s3=0;const s4=-100;const s5=0;const s6=0;const s7=0;const s8=0;const s9=0;const s10=100;const s11=0;const s12=0; // vertical const s1=0;const s2=0;const s3=-100;const s4=-100;const s5=0;const s6=0;const s7=0;const s8=0;const s9=100;const s10=100;const s11=0;const s12=0; // diagonal const s1=-100;const s2=0;const s3=-100;const s4=-100;const s5=0;const s6=0;const s7=0;const s8=0;const s9=100;const s10=100;const s11=0;const s12=100; // abstract const s1=0;const s2=0;const s3=10;const s4=10;const s5=0;const s6=0;const s7=0;const s8=0;const s9=-10;const s10=-10;const s11=0;const s12=0; // frazzle const s1=-300;const s2=0;const s3=0;const s4=0;const s5=0;const s6=0;const s7=0;const s8=0;const s9=0;const s10=0;const s11=0;const s12=300; // triangled const s1=0;const s2=300;const s3=0;const s4=0;const s5=0;const s6=0;const s7=0;const s8=0;const s9=0;const s10=0;const s11=-300;const s12=0; // bowl const s1=0;const s2=0;const s3=-300;const s4=0;const s5=0;const s6=0;const s7=0;const s8=0;const s9=0;const s10=300;const s11=0;const s12=0; // right angled const s1=0;const s2=0;const s3=0;const s4=0;const s5=-1000;const s6=1000;const s7=1000;const s8=-1000;const s9=0;const s10=0;const s11=0;const s12=0; // intense diagonal */ function createNewCurve(curve) { const builder = CurveBuilder.create(); const firstPoint = curve.beziers.first?.start; if (!firstPoint) return; builder.begin(firstPoint); for (const bez of curve.beziers) { const t = bez.getParamAtLength(bez.length * 0.5); const curves = bez.split(t); builder.addBezierXY(curves.left.c1.x+m1*s1, curves.left.c1.y+m1*s2, curves.left.c2.x+m1*s3, curves.left.c2.y+m1*s4, curves.left.end.x+m1*s5, curves.left.end.y+m1*s6); builder.addBezierXY(curves.right.c1.x+m2*s7, curves.right.c1.y+m2*s8, curves.right.c2.x+m2*s9, curves.right.c2.y+m2*s10, curves.right.end.x+m2*s11, curves.right.end.y+m2*s12); } return builder.createCurve(); } function createNewPolyCurve(polyCurve) { const newPolyCurve = PolyCurve.create(); for (const curve of polyCurve) { const newCurve = createNewCurve(curve); if (newCurve) { newPolyCurve.addCurve(newCurve); } } return newPolyCurve; } function addPoints(polyCurveNodes) { const cmds = []; for (const polyCurveNode of polyCurveNodes) { const newPoly = createNewPolyCurve(polyCurveNode.polyCurve); if (newPoly.curveCount > 0) { cmds.push(DocumentCommand.createSetCurves(polyCurveNode.curvesInterface, newPoly)); } } if (cmds.length == 0) return; if (cmds.length == 1) doc.executeCommand(cmds[0]); else { const builder = CompoundCommandBuilder.create(); for (const cmd of cmds) { builder.addCommand(cmd); } doc.executeCommand(builder.createCommand()); } } function main() { if (!doc) { alert("This script requires an open document"); return; } const nodes = doc.selection.nodes.filter(node => node.isPolyCurveNode); if (nodes.isEmpty) { alert("Select some curves"); return; } addPoints(nodes); } main();